﻿using System;
using System.Configuration;
using System.IO;

namespace YasharEl.Infrastructure.Configuration.Validators
{
    public class DirectoryValidator : ConfigurationValidatorBase
    {
        #region ConfigurationValidatorBase Implementation

        public override bool CanValidate(Type type)
        {
            return (type == typeof(string));
        }

        public override void Validate(object value)
        {
            try
            {
                if (!Directory.Exists(value.ToString()))
                {
                }
            }
            catch (Exception e)
            {
                throw new ConfigurationErrorsException(
                    string.Format("Directory {0} not valid.",value), e);
            }
        }

        #endregion
    }

    public class DirectoryValidatorAttribute : ConfigurationValidatorAttribute
    {
        #region ConfigurationValidatorAttribute Overrides

        public override ConfigurationValidatorBase ValidatorInstance
        {
            get
            {
                return new DirectoryValidator();
            }
        }

        #endregion
    }
}
